package com.amumu.drama.admin.modules.member.mapping;

import com.amumu.drama.admin.modules.member.dto.resp.UmsMemberListResp;
import com.amumu.drama.common.base.mapstruct.BaseMapping;
import com.amumu.drama.common.constant.InvitationTypeEnum;
import com.amumu.drama.common.dto.OrderStatisticsDTO;
import com.amumu.drama.common.modules.invitation.cache.InvitationOrderStatisticsCache;
import com.amumu.drama.model.UmsMember;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
 * @author sunzhuang
 * @date 2024/9/12 15:12
 * @slogan 天下风云出我辈, 一入代码岁月催
 * @desc todo
 */
@Mapper(componentModel = "spring")
public interface UmsMemberListRespMapping extends BaseMapping<UmsMember, UmsMemberListResp> {
    UmsMemberListRespMapping INSTANCE = Mappers.getMapper(UmsMemberListRespMapping.class);

    /**
     * 正向映射的后置处理，List映射会自动继承此配置
     *
     * @param src
     * @param dest
     */
    @Override
    default void afterConvertTo(UmsMember src, UmsMemberListResp dest) {
        OrderStatisticsDTO statisticsDTO = InvitationOrderStatisticsCache.INSTANCE.getInvitationOrderStatisticsFromCache(InvitationTypeEnum.MEMBER.getCode(), src.getId() + "");
        if (statisticsDTO != null) {
            dest.setInvitationMemberCount(statisticsDTO.getInvitationMemberCount());
            dest.setOrderCount(statisticsDTO.getOrderCount());
            dest.setTotalAmount(statisticsDTO.getTotalAmount());
        }
    }
}
